{	Problem: http://codeforces.ru/problemset/problem/62/B
	Verdict: Accepted

}
const bad=maxlongint;
var i,j,k:longint; c,n,m,g:int64; s,t:string; b:array['a'..'z'] of longint; a:array['a'..'z',1..100010] of longint;
begin
readln(n,k);
readln(s);
for i:=1 to k do begin
   inc(b[s[i]]);
   a[s[i]][b[s[i]]]:=i;
end;
for i:=1 to n do begin
    c:=0;
    readln(t);
    m:=length(t);
    for j:=1 to m do begin
        g:=bad;
        for k:=1 to b[t[j]] do
            if g>abs(a[t[j]][k]-j) then g:=abs(a[t[j]][k]-j);
        if g=bad then g:=m;
        inc(c,g);
    end;
    writeln(c);
end;
end.  var i,j,k:longint; c,n,m,g:int64; s,t:string; b:array['a'..'z'] of longint; a:array['a'..'z',1..100010] of longint;
begin
readln(n,k);
readln(s);
for i:=1 to k do begin
   inc(b[s[i]]);
   a[s[i]][b[s[i]]]:=i;
end;
for i:=1 to n do begin
    c:=0;
    readln(t);
    m:=length(t);
    for j:=1 to m do begin
        g:=m;
        for k:=1 to b[t[j]] do
            if g>abs(a[t[j]][k]-j) then g:=abs(a[t[j]][k]-j);
        inc(c,g);
    end;
    writeln(c);
end;
end.  